﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Security.Cryptography;
using System.Text;

namespace wuliuback
{
    public partial class QueryTrace : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string userId = Request["user_id"];
            string pageSize = Request["page_size"];
            string minId = Request["min_id"];
            if (userId == null || userId.Length <= 0)
            {
                return;
            }
            string code = "";
            string msg = "";
            string trace = "";

            string curMinId = "";

            DbHelper dbHelper = new DbHelper();
            String sql = "";
            sql = "select top (" + pageSize + ") * from t_course_trace where user_id='"+userId+"' ";
            if (minId != null && minId.Length > 0)
            {
                sql = sql + " and trace_id < " + minId;
            }
            sql = sql + " order by time desc";
            string sql1 = "select min(t.trace_id) as min_id from (" + sql + ") t";


            DataSet dataSet = dbHelper.Select(sql1);
            DataTable table = dataSet.Tables[0];
            if (table.Rows.Count > 0)
            {
                curMinId = table.Rows[0][0].ToString();
            }

            DataSet dataSet1 = dbHelper.Select(sql);
            DataTable table1 = dataSet1.Tables[0];

            code = "0";
            trace = JsonUtil.DataTableToJson(table1);

            Response.Output.WriteLine("{\"code\":\"" + code + "\",\"msg\":\"" + msg
                                    + "\",\"min_id\":\"" + curMinId + "\",\"page_size\":\"" + pageSize + "\",\"user_id\":\"" + userId
                                    + "\",\"info\":" + trace + "}");
        }
    }
}
